// pages/educationExp/educationExp.js
// pages/carInfo/carInfo.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formlist: [
      { label: '高中', type: 'label' },
      { isrequire: false, label: '学校名称', key: 'highSchoolName', valueType: 'text', tips: '请填写', type: 'input' },
      { isrequire: false, label: '入学时间', key: 'highSchoolStart', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { isrequire: false, label: '毕业时间', key: 'highSchoolEnd', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { label: '大学', type: 'label' },
      { isrequire: false, label: '学校名称', key: 'universityName', valueType: 'text', tips: '请选择', type: 'input' },
      { isrequire: false, label: '入学时间', key: 'universityStart', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { isrequire: false, label: '毕业时间', key: 'universityEnd', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { label: '研究生', type: 'label' },
      { isrequire: false, label: '学校名称', key: 'graduateStudentName', valueType: 'text', tips: '请选择', type: 'input' },
      { isrequire: false, label: '入学时间', key: 'graduateStudentStart', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { isrequire: false, label: '毕业时间', key: 'graduateStudentEnd', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { label: '最高学历', type: 'label' },
      { isrequire: false, label: '学校名称', key: 'topSchoolName', valueType: 'text', tips: '请选择', type: 'input' },
      { isrequire: false, label: '入学时间', key: 'topSchoolStart', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
      { isrequire: false, label: '毕业时间', key: 'topSchoolEnd', valueType: 'text', tips: '请选择', type: 'select', mode: 'date' },
    ],
    formData: {
      highSchoolName: "",
      highSchoolStart: '',
      highSchoolEnd: '',
      universityName: '',
      universityStart:'',
      universityEnd:'',
      graduateStudentName:'',
      graduateStudentStart:'',
      graduateStudentEnd:'',
      topSchoolName:'',
      topSchoolStart:'',
      topSchoolEnd:''
    },
    userInfo: '',
    inputShow: false,
    key: 'name',
    valueType: 'text',
    currentInput: {},
    active: '',
    isHome:false
  },
  bindPickerChange: function (e) {
    var item = e.currentTarget.dataset.item;
    if (item.data) {
      this.data.formData[item.key] = item.data[e.detail.value]
    } else {
      this.data.formData[item.key] = e.detail.value
    }
    this.setData({
      formData: this.data.formData
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (options.isHome) {
      this.setData({
        isHome: true
      })
    }
    wx.getStorage({
      key: 'personalInfo',
      success: function (res) {
        for(var j in that.data.formData){
          for (var j in that.data.formData) {
            if (res.data[j] != undefined) {
              that.data.formData[j] = res.data[j];
            } else {
              res.data[j] = that.data.formData[j];
            }
          }
        }
        that.setData({
          userInfo: JSON.parse(wx.getStorageSync('userInfo')),
          formData: res.data
        })
      }
    })
  },
  saveEducation: function (e) {
    wx.setStorage({
      key: 'personalInfo',
      data: this.data.formData,
    })
    wx.navigateBack({
      delta:1
    })
    // if (this.data.isHome) {
    //   wx.navigateTo({
    //     url: "/pages/perfectInfo/perfectInfo?flag=true&isHome"
    //   })
    // } else {
    //   wx.navigateTo({
    //     url: "/pages/perfectInfo/perfectInfo?flag=true"
    //   })
    // }
  },
  changeTextarea: function (e) {//输入框值改变事件
    var key = e.target.dataset.value;
    this.data.formData[key] = e.detail.value;
    this.setData({
      formData: this.data.formData
    })
    this.changeValue();
  },
  bingInputFunc: function (e) {//输入框值改变事件
    if (e.detail.value == '') {
      this.setData({
        active: ''
      })
    }
    else {
      this.setData({
        active: 'active'
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})